﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CXedu.Business;
using CXedu.Model;
using System.Collections;
using Ajeelee.Core.Database;
using CXedu.WebSite.Code;
using Ajeelee.Core.Utils;

namespace CXedu.WebSite
{
    public partial class list : System.Web.UI.Page
    {
        protected int cid;
        Hashtable table = new Hashtable();
        protected IList<News> newsList = new List<News>();
        protected NewsClass newsClass = new NewsClass();

        INewsBusiness newsBll = new NewsBusinessFactory().CreateNewsBusiness();

        protected PageStructure ps = new PageStructure() { CurrPage = 1, PageSize = 16 };

        protected void Page_Load(object sender, EventArgs e)
        {
            // 接收参数
            cid = Convert.ToInt32(Request.QueryString["c"]);
            if (Convert.ToInt32(Request.QueryString["page"]) > 1)
            {
                ps.CurrPage = Convert.ToInt32(Request.QueryString["page"]);
            }

            if (cid > 0)
            {
                try
                {
                    // 读取分页数据
                    table.Add(NewsHash.CId, cid);
                    table.Add(NewsHash.OrderField, "Top");
                    table.Add(NewsHash.OrderDirection, "desc,N_Id desc");
                    newsList = newsBll.GetAllNewsByPage(table, ps);
                    this.pager.PageStruct = ps;

                    // 读取分类信息
                    newsClass = Utility.GetNewsClass().FirstOrDefault(c => c.Id == cid);
                    if (newsClass == null)
                    {
                        newsClass = new NewsClass();
                    }

                    // 处理导航
                    NavigationType currNav = NavigationType.Index;
                    if (Enum.IsDefined(typeof(NavigationType), "List_" + +cid))
                    {
                        currNav = (NavigationType)Enum.Parse(typeof(NavigationType), "List_" + +cid);
                    }
                    else if (Utility.GetNewsClass().Count(c => c.Id == cid && c.PId == 15) > 0)
                    {
                        currNav = NavigationType.Train;
                    }
                    else if ("2,3,4,5".Contains(cid.ToString()))
                    {
                        currNav = NavigationType.AdultEdu;
                    }
                    this.header1.CurrentNavType = this.right1.CurrentNavType = currNav;
                }
                catch (Exception ex)
                {
                    Function.WriteErrorLog(ex);
                }
            }
        }
    }
}